<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:thSys="">
<div th:replace="admin/module/macros :: head('友链管理')"></div>
<body class="app sidebar-mini rtl">
	<main class="app-content">
	<div th:replace="admin/module/macros :: header"></div>
	<div th:replace="admin/module/macros :: sidebar"></div>
	<div class="app-title">
		<div>
			<h1>友情链接</h1>
		</div>
		<ul class="app-breadcrumb breadcrumb">
			<li class="breadcrumb-item"><a href="/admin"><i
					class="fa fa-home fa-lg"></i></a></li>
			<li class="breadcrumb-item"><a href="/admin/links">友情链接</a></li>
		</ul>
	</div>
	<div class="row">
		<div class="col-md-12">
			<div class="tile">
				<div class="row">
					<div class="col-lg-5">
						<th:block th:if="${link} == null ">
							<h4 class="tile-title">添加友情链接</h4>
						</th:block>
						<th:block th:if="${link} != null">
							<h4 class="tile-title">修改友情链接</h4>
						</th:block>
						<form id="linkFrom" action="/admin/links/save" method="post"
							autocomplete="off">
							<input type="hidden" name="linkId" id="linkid"
								th:value="${link!=null ? link.linkId :''}">
							<div class="form-group">
								<label class="col-form-label">*网站名称<span
									data-toggle="tooltip" data-placement="top" title="好友的网站名称"
									style="cursor: pointer"> <i
										class="fa fa-question-circle" aria-hidden="true"></i>
								</span></label> <input class="form-control" id="linkName"
									th:value="${link!=null ? link.linkName :''}" name="linkName"
									type="text">
							</div>
							<div class="form-group">
								<label class="col-form-label">*网址<span
									data-toggle="tooltip" data-placement="top"
									title="*需要加上http://或https://" style="cursor: pointer"> <i
										class="fa fa-question-circle" aria-hidden="true"></i>
								</span></label> <input class="form-control" id="linkUrl"
									th:value="${link!=null ? link.linkUrl : ''}" name="linkUrl"
									type="text">
							</div>
							<div class="form-group">
								<label class="col-form-label">LOGO<span
									data-toggle="tooltip" data-placement="top"
									title="LOGO链接地址，需要加上http://或https://" style="cursor: pointer">
										<i class="fa fa-question-circle" aria-hidden="true"></i>
								</span></label> <input class="form-control" id="linkLogo"
									th:value="${link!=null ? link.linkLogo : ''}" name="linkLogo"
									type="text">
							</div>
							<div class="form-group">
								<label class="col-form-label">描述<span
									data-toggle="tooltip" data-placement="top" title="网站的描述"
									style="cursor: pointer"> <i
										class="fa fa-question-circle" aria-hidden="true"></i>
								</span></label>
								<textarea class="form-control" rows="3" id="linkDescribe"
									th:text="${link != null ? link.linkDescribe : ''}"
									th:value="${link != null ? link.linkDescribe : ''}"
									name="linkDescribe" style="resize: none"></textarea>
							</div>
							<div class="tile-footer">
								<button class="btn btn-sm btn-outline-primary" type="submit">保存链接</button>
								<th:block th:if="${link} != null">
									<a class="btn btn-sm btn-outline-info" href="/admin/links">返回添加</a>
								</th:block>
							</div>
						</form>
					</div>
					<div class="col-lg-7">
						<h4 class="tile-title">所有友情链接</h4>
						<div class="table-responsive">
							<table class="table table-striped table-hover table-condensed">
								<thead>
									<tr>
										<td>网站名称</td>
										<td>网址</td>
										<td>描述</td>
										<td>操作</td>
									</tr>
								</thead>
								<tbody>
									<tr th:each="link : ${links}">
										<td th:text="${link.linkName}"></td>
										<td th:text="${link.linkUrl}"></td>
										<td th:text="${link.linkDescribe}"></td>
										<td><a class="btn btn-sm btn-outline-primary"
											th:href="@{/admin/links/edit(linkId=${link.linkId})}">修改</a>
											<button class="btn btn-sm btn-outline-danger"
												th:onclick="'javascript:showModel('+${link.linkId}+')'">删除</button>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</main>
	<div th:replace="admin/module/macros :: remove"></div>
	<div th:replace="admin/module/macros :: comm"></div>
	<div th:replace="admin/module/macros :: bootstrapValidator"></div>
	<script type="text/javascript">
	$(function(){
		$("form").bootstrapValidator({
			message: 'This value is not valid',
           　		feedbackIcons: {
               　　　　　　　　valid: 'glyphicon glyphicon-ok',
               　　　　　　　　invalid: 'glyphicon glyphicon-remove',
               　　　　　　　　validating: 'glyphicon glyphicon-refresh'
           　　　　　　　　   },
            fields: {
        	   linkName: {
                   message: '网站名称验证失败',
                   validators: {
                       notEmpty: {
                           message: '网站名称不能为空'
                       }
                   }
               },
               linkUrl: {
            	   message: '网址验证失败',
                   validators: {
                       notEmpty: {
                           message: '网址不能为空'
                       }
                   }
               }
           }
		});
	});
		function showModel(linkId) {
			$("#linkid").val(linkId);
			$("#removeModal").modal();
		}
		function remove() {
			window.location.href = "/admin/links/remove?linkId="
					+ $("#linkid").val();
		}
		
		
	</script>
</body>
</html>